<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 准备好一个容器-->
<div id="root" :x="n">
    <h2 v-text="n"></h2>
    <h2>当前的n值是：{{n}}</h2>
    <button @click="add">点我n+1</button>
    <button @click="bye">点我销毁vm</button>
</div>
</body>

<script>
    new Vue({
        el: '#root',
        /*template: `
          <div>
            <h2 v-text="n"></h2>
            <h2>当前的n值是：{{n}}</h2>
            <button @click="add">点我n+1</button>
            <button @click="bye">点我销毁vm</button>
          </div>
        `,*/
        data: {
            n: 1
        },
        methods: {
            add() {
                console.log('add')
                this.n++
            },
            bye() {
                console.log('bye')
                this.$destroy()
            }
        },

        beforeCreate() {
            console.log('beforeCreate')
            console.log(this)

        },
        created() {
            console.log('created')
            console.log(this)
        },

        beforeMount() {
            console.log('beforeMount')
            console.log(this)
        },

        mounted() {
            console.log('mounted')
            console.log(this)

        },

        beforeUpdate() {
            console.log('beforeUpdate')
            console.log(this.n)
            // debugger
        },

        updated() {
            console.log('updated')
            console.log(this.n)
            // debugger
        },

        beforeDestroy() {
            console.log('beforeDestroy')
            this.add()
        },

        destroyed() {
            console.log('destroyed')
            console.log(this)
        }
    })
</script>
</html>